<template>
  <div class="layout">
    <Layout :style="{minHeight: '100vh'}">
      <Sider ref="side1" hide-trigger collapsible :collapsed-width="78" v-model="isCollapsed">
        <div class="logo-con">
          <img v-show="!isCollapsed" :src="maxLogo" key="max-logo" />
          <img v-show="isCollapsed" :src="minLogo" key="min-logo" />
        </div>
        <i-menu accordion theme="dark" width="auto" :class="menuitemClasses">
          <Menu-item name="0" to="/index">
            <Icon type="md-globe"></Icon>
            <span>首页统计</span>
          </Menu-item>
          <Submenu name="1">
            <template slot="title">
              <Icon type="ios-contacts" />
              图书借阅
            </template>
            <Menu-item to="/index/loan-management" name="1-1">
              <Icon type="ios-list"></Icon>
              出借管理
            </Menu-item>
            <Menu-item to="/index/return-book" name="1-2">
              <Icon type="ios-person" />
              归还图书
            </Menu-item>
            <Menu-item to="/index/advance-management" name="1-3">
              <Icon type="ios-person" />
              预借管理
            </Menu-item>
            <Menu-item to="/index/borrowing-history" name="1-4">
              <Icon type="ios-person" />
              借阅历史
            </Menu-item>
          </Submenu>
          <Submenu name="2">
            <template slot="title">
              <Icon type="ios-contact" />
              读者管理
            </template>
            <Menu-item to="/index/reader-information" name="2-1">
              <Icon type="ios-list"></Icon>
              读者信息
            </Menu-item>
            <Menu-item to="/index/reader-identity" name="2-2">
              <Icon type="ios-list"></Icon>
              读者等级
            </Menu-item>
          </Submenu>
          <Submenu name="3">
            <template slot="title">
              <Icon type="ios-school" />
              书籍管理
            </template>
            <Menu-item to="/index/book-list" name="3-1">
              <Icon type="ios-list"></Icon>
              书籍列表
            </Menu-item>
            <Menu-item to="/index/book-class" name="3-2">
              <Icon type="ios-person" />
              图书分类
            </Menu-item>
            <Menu-item to="/index/book-press" name="3-3">
              <Icon type="ios-person" />
              出版社
            </Menu-item>
          </Submenu>
          <Submenu name="4" v-if="role">
            <template slot="title">
              <Icon type="ios-cog" />
              系统设置
            </template>
            <Menu-item to="/index/users" name="4-1">
              <Icon type="ios-list"></Icon>
              用户管理
            </Menu-item>
            <Menu-item to="/index/role" name="4-2">
              <Icon type="ios-list"></Icon>
              角色管理
            </Menu-item>
            <Menu-item to="/index/permissions" name="4-3">
              <Icon type="ios-list"></Icon>
              权限管理
            </Menu-item>
            <Menu-item  to="/index/stores" name="4-4">
              <Icon type="ios-person" />
              门店列表
            </Menu-item>
            <Menu-item to="/index/the-log" name="4-5">
              <Icon type="ios-list"></Icon>
              操作日志
            </Menu-item>
          </Submenu>
        </i-menu>
      </Sider>
      <Layout>
        <Header :style="{padding: 0}" class="layout-header-bar">
          <Icon @click.native="collapsedSider" @on-coll-change="handleCollapsedChange" :class="rotateIcon" :style="{margin: '0 20px'}" type="md-menu" size="24"></Icon>
          <Dropdown style="margin-right: 40px;float: right;" @on-click="handleClick">
            <a href="javascript:void(0)">{{ name }}
              <Icon type="ios-arrow-down"></Icon>
            </a>
            <DropdownMenu slot="list">
              <DropdownItem name="password">修改密码</DropdownItem>
              <DropdownItem divided name="logout">退出系统</DropdownItem>
            </DropdownMenu>
          </Dropdown>
          <fullscreen v-model="isFullscreen" style="float:right;margin-right: 25px;"/>
        </Header>
        <Content :style="{margin: '20px', background: '#fff', minHeight: '260px'}">
          <router-view></router-view>
        </Content>
        <Footer style="padding-left: 20px !important;padding-bottom: 10px !important;padding-top: 0px !important;">
          <div style="float: left;">凤翮正道技术部 &copy;2018 版权所有 侵权必究</div>
          <div style="float: right;"><Button type="primary" icon="ios-bug" style="font-size: 15px;" @click="bugReport">BUG提交</Button></div>
        </Footer>
      </Layout>
    </Layout>
  </div>
</template>

<script>
  import Fullscreen from '@/components/fullscreen'
  import minLogo from '@/assets/images/logo-min.png'
  import maxLogo from '@/assets/images/logo.png'
  import avatar from '@/assets/images/avatar.jpg'
  export default {
    components: {
      Fullscreen
    },
    data () {
      return {
        side1: '',
        role: false,
        isCollapsed: false,
        isFullscreen: false,
        name: 'admin',
        minLogo,
        maxLogo,
        avatar
      }
    },
    computed: {
      rotateIcon () {
        return [
          'menu-icon',
          this.isCollapsed ? 'rotate-icon' : ''
        ]
      },
      menuitemClasses () {
        return [
          'menu-item',
          this.isCollapsed ? 'collapsed-menu' : ''
        ]
      }
    },
    mounted() {
      if (sessionStorage.getItem('role') === 'admin') {
        this.role = true
      } else {
        this.role = false
      }
    },
    methods: {
      handleClick (name) {
        if (name === 'password') {
          this.$router.push('/index/reset')
        } else {
          localStorage.removeItem('access_token')
          this.$router.push('/login')
        }
      },
      collapsedSider () {
        this.$refs.side1.toggleCollapse()
      },
      handleCollapsedChange (state) {
        this.isCollapsed = state
      },
      bugReport () {
        this.$Modal.confirm({
          title: '提示',
          content: '<p>请发送邮件至<a href="mailto:huchengye@fhdream.com">huchengye@fhdream.com</a>报告BUG，注意提交BUG截图，谢谢！</p>',
          onOk: () => {
            window.location.href = 'mailto:huchengye@fhdream.com'
          }
        })
      }
    }
  }
</script>

<style scoped>
  .logo-con{
    height: 64px;
    padding: 10px;
  }
  .logo-con img{
    height: 44px;
    width: auto;
    display: block;
    margin: 0 auto;
  }
  .layout-con{
    height: 100%;
    width: 100%;
  }
  .layout{
    background: #f5f7f9;
    position: relative;
    border-radius: 0px;
    overflow: hidden;
  }
  .layout-header-bar{
    background: #fff;
    box-shadow: 0 1px 1px rgba(0,0,0,.1);
  }
  .layout-logo-left{
    width: 90%;
    height: 30px;
    background: #5b6270;
    border-radius: 3px;
    margin: 15px auto;
  }
  .menu-icon{
    transition: all .3s;
  }
  .rotate-icon{
    transform: rotate(-90deg);
  }
  .menu-item span{
    display: inline-block;
    overflow: hidden;
    width: 69px;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
    transition: width .2s ease .2s;
  }
  .menu-item i{
    transform: translateX(0px);
    transition: font-size .2s ease, transform .2s ease;
    vertical-align: middle;
    font-size: 16px;
  }
  .collapsed-menu span{
    width: 0px;
    transition: width .2s ease;
  }
  .collapsed-menu i{
    transform: translateX(5px);
    transition: font-size .2s ease .2s, transform .2s ease .2s;
    vertical-align: middle;
  }
</style>
